package com.appspot.categoryeditor.resource;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.StreamingOutput;

public class JspPage implements StreamingOutput {

	private String page;
	private HttpServletRequest req;
	private HttpServletResponse resp;

	public JspPage(String page, HttpServletRequest req, HttpServletResponse resp) {
		super();
		this.page = page;
		this.req = req;
		this.resp = resp;
	}

	@Override
	public void write(OutputStream arg0) throws IOException,
			WebApplicationException {

		try {
			req.getRequestDispatcher(page).forward(req, resp);
		} catch (ServletException e) {
			throw new WebApplicationException();
		}
	}

}
